package cn.fengzhilun.httpclient;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class TestHttpClient {
	public static void main(String[] args) {
		CloseableHttpClient httpClient = HttpClients.createDefault();
		 HttpGet get = new HttpGet("http://dudj.net/hongsejingdian/27/");
		 try(
				 CloseableHttpResponse response = httpClient.execute(get);	 
				 ) {
			HttpEntity entity = response.getEntity();
			String string = EntityUtils.toString(entity,"UTF-8");
			//System.out.println(string);
			String regex ="^<a .*>.*</a>";
			Pattern pattern = Pattern.compile(regex);       // regex是你要写的正则表达式
		    Matcher matcher = pattern.matcher(string);      // source是待搜索的字符串（这里是网页内容）
		    
//		    while (matcher.find()) {
//		        int start = matcher.start();
//		        int end = matcher.end();
//		        
//		        
//				String a = strSource.substring(start, end);   //  a是匹配到的一个子串
//		        System.out.println(a);
//		    }
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
